// Promise

/*
let p1 = new Promise((resolve, reject) => {
    resolve("成功");
});

console.log(p1);

p1.then(res => {
    console.log(res);
}, err => {
    console.log(err);
});

let p2 = new Promise((resolve, reject) => {
    reject("失败");
});

console.log(p2);

p2.then(res => {
    console.log(res);
}, err => {
    console.log(err);
});

let p3 = new Promise((resolve, reject) => {
    if (true) {
        resolve("成功");
    } else {
        reject("失败");
    }
});

// 链式写法
p3.then(res => {
    console.log(res);
}).catch(err => {
    console.log(err);
});

*/

// Promise 对象的状态改变，只有两种可能：要么从 Pending -> Fulfilled；要么 Pending -> Rejected。只要这两种情况发生，状态就不会再变了，会一直保持这个结果。

let p4 = new Promise((resolve, reject) => {
    reject("失败"); // Penging -> Rejected
    resolve("成功"); // 不会执行，因为Promise对象一旦状态改变，就不会再变。
});

p4.then(res => {
    console.log(res);
}).catch(err => {
    console.log(err);
})